﻿using System;
using System.Linq;

namespace HamcoWcs.Models.Monitors
{
    /// <summary>
    /// 电机里程
    /// </summary>
    public class MotorMileage : ParaBase
    {
        public string DeviceType { get; set; }
        public Int32 Mileage { get; set; }
        public Int32 Mileage2 { get; set; }

        public string MachineName { get; set; }
        public string PortName { get; set; }

        public MotorMileage(int index, string name, string machineName,string portName, string deviceType = "pcon") : base(index, name)
        {
            DeviceType = deviceType;
            MachineName = machineName;
            PortName = portName;
        }
        protected override int _len => 2;

        public override void Update(byte[] content)
        {
            var t = GetTargetContent(content);
            Mileage = Reserve(BitConverter.ToInt16(t, 0));
        }

        public  void UpdateSrm(byte[] content)
        {
            //var t = GetTargetContent(content);
            if (content is null)
                return;
            try
            {
                var t = content.Skip(_index).Take(4).ToArray();
                Mileage = (BitConverter.ToInt32(t, 0));
            }
            catch (Exception)
            {

            }
           
        }
    }
}
